/*==================================================
Project:       Targeting Social Programs
Authors:       Diether W. Beuermann
               Bridget Hoffmann        
               Marco Stampini 
               David L. Vargas
               Diego Vera-Cossio
----------------------------------------------------
Creation Date:    
Modification Date:   
Do-file version:    01
References:          
Output:             
==================================================*/


/*==================================================
            0: Program set up
==================================================*/
*Written on STATA 17
drop _all

** source dir
cd "${dir4r}" // tables dir

*----------  1.1. Estimate PMT coefficients for population data
* For convenience all pmt relevant coefficients are availible in a aux dta *
use "${dir3r}/01_survey/survey_targeting_r1_long.dta", clear

* new interactions 
cap drop d_loss_illness_inc
cap drop d_reco_ilness_inc
gen d_loss_illness_inc = illness_incidence * d_loss_ilness
gen d_reco_ilness_inc = lag_illness_incidence * d_reco_ilness
lab var d_loss_illness_inc	"Loss: Illness Incidence"
lab var d_reco_ilness_inc	"Recovery: Illness Incidence"


cap drop d_loss_cut_remittance_inc
cap drop d_reco_cut_remittance_inc
gen d_loss_cut_remittance_inc = cut_remittance_incidence * d_loss_cut_remittance
gen d_reco_cut_remittance_inc = lag_cut_remittance_incidence * d_reco_cut_remittance
lab var d_loss_cut_remittance_inc "Loss: Remittances Cut Incidence"
lab var d_reco_cut_remittance_inc "Recovery: Remittances Cut Incidence"

* Globals with shocks
glo loss_rec      d_reco_ilness d_loss_ilness d_reco_cut_remittance d_loss_cut_remittance death divorce bankrupt nat_shock 
glo loss_inc      illness_incidence cut_remittance_incidence death divorce bankrupt nat_shock 
glo loss_rec_inc  d_loss_illness_inc d_reco_ilness_inc d_loss_cut_remittance_inc d_reco_cut_remittance_inc death divorce bankrupt nat_shock 

** make sure all labels are OK 
lab var illness_incidence 			"Illness Incidence"
lab var cut_remittance_incidence 	"Remittances Cut Incidence"
lab var death						"Death"
lab var divorce					"Separation of Spouses"
lab var bankrupt					"Bankruptcy or Business Closure"
lab var nat_shock					"Natural Disaster or Fire"
lab var job_loss                   "Loss: Job lost at any point of the year"
lab var job_loss_formal            "Loss: Job lost formal at any point of the year"
lab var job_loss_informal          "Loss: Job lost informal at any point of the year"


global ord "d_gain_work_any_srv d_loss_work_any_srv job_loss d_gain_formal_work_srv d_loss_formal_work_srv job_loss_formal d_gain_informal_work_srv d_loss_informal_work_srv job_loss_informal d_reco_ilness d_loss_ilness d_reco_cut_remittance d_loss_cut_remittance d_loss_illness_inc d_reco_ilness_inc d_loss_cut_remittance_inc d_reco_cut_remittance_inc illness_incidence cut_remittance_incidence death divorce bankrupt nat_shock"

// dumb minors
lab var d_work_any_srv "Change: Work status"

//>>>>>>>>>>> 1.1. Estimation

*** Simple changes to changes 
reg d_income_nt d_work_any_srv [aw=pondera] if  !missing(l_pp_inc_srv), nocons robust
outreg using "TA4_labour_dynamic.tex", replace varlabel frag tex se ct("", "(1)") starlevels(10 5 1)

*** Gain and losses
reg d_income_nt d_gain_work_any_srv d_loss_work_any_srv [aw=pondera] if   !missing(l_pp_inc_srv), nocons robust
outreg using "TA4_labour_dynamic.tex", merge varlabel frag tex se ct("", "(2)") starlevels(10 5 1)

*** Gain and losses w/ formal and informal 
reg d_income_nt d_gain_formal_work_srv d_loss_formal_work_srv d_gain_informal_work_srv d_loss_informal_work_srv [aw=pondera] if  !missing(l_pp_inc_srv), nocons robust
outreg using "TA4_labour_dynamic.tex", merge varlabel frag tex se ct("", "(3)") starlevels(10 5 1)